package day06;

import java.util.Arrays;

/**
 * @author zdl
 * @date 2024/11/8
 */
public class Demo8 {

    public static void main(String[] args) {
        /**
         * 删除数组指定元素  [1,2,3,4,5] --> [1,2,4,5]
         *                 ===>[1,2,4,4,5]
         *                 ===>[1,2,4,5,5]
         *                   ==>[1,2,4,5]
         */
        int[] arr = {1, 2, 3, 4, 5, 3, 4, 5};
        int count = 0; //记录指定值重复次数
        for (int i = 0; i < arr.length; i++) {
            if (3 == arr[i]) {
                count++;
            }
        }
        int index = 0;
        int[] new_arr = new int[arr.length - count];  //定义新数组，接收移除后的数组
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != 3) {
                new_arr[index++] = arr[i];
            }
        }
        System.out.println(Arrays.toString(new_arr));
    }

}
